const float kFalloffMult = 0.04;
const float kFalloffExp = 0.375;

uniform sampler2D texture;
uniform vec3 lightPos;

varying float kDiffuse;
varying float kFalloff;

vec3 getECLightPosition(vec3 lightPosN) {
	vec4 posLightN4 = vec4(lightPosN, 1.0);
	vec3 posLightN_EC = (gl_ModelViewMatrix * posLightN4).xyz;
	return posLightN_EC;
}

float vlengthPow(vec3 vc, float exponent) {
	return pow(vc.x * vc.x + vc.y * vc.y + vc.z * vc.z, exponent);
}

void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    
    vec3 nvecNorm = normalize(gl_NormalMatrix * gl_Normal);
    vec3 posVertEC = (gl_ModelViewMatrix * gl_Vertex).xyz;
    
    vec3 posLightEC = getECLightPosition(lightPos);
    vec3 vecVtoL = posLightEC - posVertEC;
    vec3 nvecLight = normalize(vecVtoL);
    float nDotL = dot(nvecLight, nvecNorm);
    kDiffuse = max(nDotL, 0.0);
    
    kFalloff = 1.0 - kFalloffMult * vlengthPow(vecVtoL, kFalloffExp);
    
}